/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 2;

int a[maxn];

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int l = 1, r = n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    if (n == 2) {
      if (a[1] == 1 && a[2] == 0) {
        cout << 1 << '\n';

      } else {
        cout << 0 << '\n';
      }
      continue;
    }
    int ans = 0;
    while (l != r) {
      while (l != r && a[l] != 1) {
        ++l;
      }
      if (l == r) break;
      while (l != r && a[r] != 0) {
        --r;
      }
      if (l == r) break;
      ++ans;
      if (l == r - 1) break;
      ++l, --r;
    }
    cout << ans << '\n';
  }

  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Rebellion.in", "r", stdin);
  freopen("B. Rebellion.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
